package com.company.Lab2;

import java.util.Scanner;

public class ExpectantaBayes {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double[][] bayes;
        double[] prob;
        double[] sum;
        int r, c;
        double result;

        System.out.print("Introduceti numarul de randuri : ");
        r = scanner.nextInt();
        System.out.print("Introduceti numarul de coloane : ");
        c = scanner.nextInt();
//        init arrays
        bayes = new double[r][c];
        prob = new double[c];
        sum = new double[r];
//        read array bayes
        System.out.println("Introduceti matricea :");
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print("[" + i + "]" + "[" + j + "] : ");
                bayes[i][j] = scanner.nextDouble();
            }
        }
//        read prob array
        for (int i = 0; i < c; i++) {
            System.out.print("Prob[" + i + "] : ");
            prob[i] = scanner.nextDouble();
        }
//        Logic
//        sum[][] = bayes[i][j] * prob[i] for each row
        for (int i = 0; i < r; i++) {
            double localProd = 0;
            double rsum = 0;
            for (int j = 0; j < c; j++) {
                localProd = bayes[i][j] * prob[j];
                rsum += localProd;
            }
            sum[i] = rsum;
        }
//        Calc max from sum[i]
        result = sum[0];
        for (double v : sum) {
            result = Math.max(result, v);
        }
        System.out.println("Rezultat final Bayes : " + result);
    }
}